package com.hl233.common.interceptor;

import com.hl233.common.constant.Constants;
import com.hl233.common.constant.SecurityConstants;
import com.hl233.common.context.SecurityContextHolder;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.AsyncHandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自定义请求头拦截器，将Header数据封装到线程变量中方便获取
 * 注意：此拦截器会同时验证当前用户有效期自动刷新有效期
 *
 * @author 张振强15065206763
 * @create 2024-09-23
 */
public class UserInfoInterceptor implements AsyncHandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String userid = request.getHeader(Constants.DETAILS_USER_ID);
        System.out.println("打印一下这个看看"+userid);
        SecurityContextHolder.setUserId(userid);
        return true;
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
            throws Exception {

    }
}
